package com.topfinance.payment.service.impl;

import java.util.*;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.topfinance.frame.dao.HibernateEntityDao;
import com.topfinance.frame.exception.AppException;
import com.topfinance.frame.util.BeanUtilsEx;
import com.topfinance.frame.util.StringUtil;
import com.topfinance.payment.ebo.*;
import com.topfinance.payment.service.*;

/**
 * 该类自动实现了dao的一般方法，如add, remove, update
 * 在service中出现的大部分情况下是在向后台提交数据前的处理(如校验)及获取后台数据后的处理等
 * @author
 *
 */

public class TC1BisEleBscMgrImpl extends HibernateEntityDao<TC1BisEleBscEbo> implements ITC1BisEleBscMgr {

	private static final Log log = LogFactory.getLog(TC1BisEleBscMgrImpl.class);

	//获得一代要素列表
	//输入的数据格式以一代为标准，否则要进行一二代数据表示转换
	public List<TC1BisEleBscEbo> getAllBisEleBsc(String msg,String tpCode,String clsCode,String eleSet) throws AppException{
		//获得基本要素集合
		String hql = " from TC1BisEleBscEbo t " ;
		String where = "";
		if(StringUtil.isNotNullStr(msg))
			where += " and t.msgCode = '" + msg + "'";
			
		List<Object> paramList = new ArrayList<Object>();
		if (isNotBlank(where)) {
			where = " where " + where.substring(4);
		}
		List<TC1BisEleBscEbo> eles = find(hql + where,paramList.toArray());
		if(msg.startsWith("CMT"))
			return eles;
		
		if(StringUtil.isNullStr(eleSet)){
			System.out.println("[Error EleSet]不能为空！");
			return eles;
		}
		
		//如果对应的是PKG，获得要素集所对应的PKG要素集
		where = " where t.msgCode = '" + eleSet + "'";
		List<TC1BisEleBscEbo> sets = find(hql + where,paramList.toArray());
		//要素集合并
		eles.addAll(sets);
		//如果类型号和种类号为空，直接返回结果
		if(StringUtil.isNullStr(tpCode)){
			return eles;
		}
		
		hql = " from TC1BisEleExtEbo e ";
		where = " where e.tpCode = '" + tpCode + "'";
		List<TC1BisEleExtEbo> exts = find(hql + where,paramList.toArray());
		for(TC1BisEleExtEbo ext:exts){
			TC1BisEleBscEbo b = new TC1BisEleBscEbo();
			BeanUtilsEx.copyProperties(ext, b);
			b.setAppType("BEPS");
			eles.add(b);
		}
		return eles;
		
	}
	
}
